<template>
  <div>
    <!-- 面包屑 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home/director-list' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>导演管理</el-breadcrumb-item>
      <el-breadcrumb-item>导演列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 分割线 -->
    <el-divider></el-divider>
    <!-- 搜索表单 -->
    <el-form :inline="true" :model="searchFrom" class="demo-form-inline">
      <el-form-item label="姓名">
        <el-input
          v-model="searchFrom.directorName"
          placeholder="请输入导演姓名"
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onDirSearch">查询</el-button>
      </el-form-item>
    </el-form>
    <!-- 导演列表 -->
    <el-divider content-position="center">导演列表</el-divider>
    <!-- 导演列表组件复用 -->
    <director-item
      v-for="item in directorList"
      :key="item.id"
      :id="item.id"
      :name="item.director_name"
      :avatar="item.director_avatar"
      @deleteDirSucess="onDirectorItem"
    />
  </div>
</template>

<script>
import DirectorItem from "@/components/DirectorItem.vue";
export default {
  components: { DirectorItem },
  data() {
    return {
      searchFrom: {
        directorName: "", //导演名字
      },
      directorList: null, //绑定导演列表
    };
  },
  methods: {
    locloadDirectorrList() {
      this.$http.DirectorApi.list({ page: 1, pagesize: 100 }).then((res) => {
        console.log(res, "导演列表添加");
        this.directorList = res.data.data;
      });
    },
    onDirectorItem() {
      console.log("没问题事件传过来了");
      this.locloadDirectorrList();
    },
    onDirSearch() {
      if (!this.searchFrom.directorName.trim()) {
        //填写的时空字符串
        this.locloadDirectorrList(); //加载演员列表
      }
      let name = this.searchFrom.directorName;
      this.$http.DirectorApi.search({ name }).then((res) => {
        console.log(res);
        if (res.data.code == 200) {
          this.directorList = res.data.data;
        }
        this.searchFrom.directorName = "";
      });
    },
  },
  created() {
    this.locloadDirectorrList();
  },
};
</script>

<style lang="scss" scoped></style>
